﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Xml;
using System.Text;

namespace TKWeb
{
	public partial class RecData3 : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			byte[] buffer = Request.BinaryRead(Request.TotalBytes);
			string strXml = System.Text.Encoding.UTF8.GetString(buffer);
			if (string.IsNullOrEmpty(strXml))
			{
				return;
			}
			XmlDocument doc = new XmlDocument();
			doc.LoadXml(strXml);

			int fileId = Convert.ToInt32(doc.DocumentElement.Attributes["fileid"].Value);
			List<MySqlParameter> pars = new List<MySqlParameter>();


			int uid =Convert.ToInt32(doc.DocumentElement["uid"].InnerText);
			int user_lvl =Convert.ToInt32(doc.DocumentElement["user_lvl"].InnerText);
			int rich_lvl =Convert.ToInt32(doc.DocumentElement["rich_lvl"].InnerText);
			int room_id =Convert.ToInt32(doc.DocumentElement["room_id"].InnerText);
			string nick =doc.DocumentElement["nick"].InnerText;
			string pic =doc.DocumentElement["pic"].InnerText;
			/*
			Global.DBAccess.GetCount("select count(*) from show_users where uid=@uid and source=@source", 
				new MySqlParameter("uid", 2),
				);
			Global.DBAccess.ExecuteNonQuery("insert into show_users(uid,source,user_lvl,rich_lvl,room_id,nick,pic,area,onlines,play_time) values(@uid,@source,@user_lvl,@rich_lvl,@room_id,@nick,@pic,@area,@onlines,@play_time)",
				new MySqlParameter(uid)
				
			);

			DataTable dt = Global.DBAccess.GetTable("select * from crawl_file_field where fileId=@fileId", new MySqlParameter[]{
				new MySqlParameter("fileId", fileId)
			});

			StringBuilder sb = new StringBuilder();
			int count = Global.DBAccess.GetCount(string.Format("select count(*) from {0} where hash=@hash", tableName), new MySqlParameter("hash", hash));
			if (count == 0)
			{
				sb.AppendFormat("insert into {0}(", tableName);
				int i = 0;
				foreach (DataRow dr in dt.Rows)
				{
					if (i > 0)
					{
						sb.Append(",");
					}
					string code = dr["code"].ToString();
					sb.Append(code);
					i++;
				}

				sb.Append(") values(");
				int j = 0;
				foreach (DataRow dr in dt.Rows)
				{
					if (j > 0)
					{
						sb.Append(",");
					}
					string code = dr["code"].ToString();
					sb.Append("@" + code);
					j++;
				}
				sb.Append(")");
			}
			else
			{
				sb.AppendFormat("update {0} set ", tableName);
				int i = 0;
				foreach (DataRow dr in dt.Rows)
				{
					if (i > 0)
					{
						sb.Append(",");
					}
					string code = dr["code"].ToString();
					sb.Append(code + "=@" + code);
					i++;
				}
				sb.Append("where hash=@hash");
			}

			pars.Add(new MySqlParameter("hash", hash));
			foreach (XmlNode n in doc.DocumentElement.ChildNodes)
			{
				pars.Add(new MySqlParameter(n.Name, n.InnerText));
			}
			Global.DBAccess.ExecuteNonQuery(sb.ToString(), pars.ToArray());
			 * */
		}

	}
}